import requests
import pprint


for page in range(1,11):
    print('=================正在爬取第{}页数据================='.format(page))
# url地址
    url = 'https://v.6.cn/minivideo/getMiniVideoList.php?act=recommend&page={}&pagesize=20'.format(str(page))
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}
    # 发送网络请求
    response = requests.get(url=url, headers=headers)
    # print(response)
    json_data = response.json()
    pprint.pprint(json_data)

    data_list = json_data['content']['list']
    for data in data_list:
        video_title = data['alias'] + '.mp4'  # 文件名
        video_url = data['playurl']  # url
        # print(video_title, video_url)
        video_data = requests.get(url=video_url, headers=headers).content

        with open('video\\' + video_title, mode='wb') as f:
            f.write(video_data)
            print("下载完成", video_title)
